import java.util.*;

/**
 * NC227310 爱吃素
 * https://ac.nowcoder.com/acm/problem/227310
 */

/**
 * AB33 相差不超过k的最多数
 * https://www.nowcoder.com/practice/562630ca90ac40ce89443c91060574c6?tpId=308&tqId=40490&ru=/exam/oj
 */
 class Main2
{
    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt(),k = in.nextInt();

        int[] arr = new int[n];

        for(int i = 1;i < n;i++) arr[i] = in.nextInt();

        //1.排序
        Arrays.sort(arr);

        //2.双指针
        int left = 0,right = 0,cnt = 1;
        while(right < n){
            while(left < right && arr[right] - arr[left] > k) left++;

            cnt = Math.max(cnt,right - left + 1);
            right++;
        }

        System.out.println(cnt);
    }
}

/**
 * 最长公共子序列（一）
 * https://www.nowcoder.com/practice/672ab5e541c64e4b9d11f66011059498?tpId=230&tqId=39761&ru=/exam/oj
 */
public class Main
{
    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt(),m = in.nextInt();

        char[] s1 = in.next().toCharArray();
        char[] s2 = in.next().toCharArray();

        int[][] dp = new int[n+1][m+1];

        for(int i = 1;i <= n;i++){
            for(int j = 1;j <= m;j++){
                if(s1[i-1] == s2[j-1]) dp[i][j] = dp[i-1][j-1] + 1;
                else dp[i][j] = Math.max(dp[i-1][j],dp[i][j-1]);
            }
        }

        System.out.println(dp[n][m]);
    }
}